include ../config.mk

dist_srcdir = Foundation
dist_FILES = \
	Foundation.conf \
	Foundation.conf-inplace \
	Makefile.in \
	$(NULL)

all: libHSFoundation.a HSFoundation.o

ghcmake: ghcmake.build-stamp

ghcmake.build-stamp:
	ln -sf ../Bindings/ifgen-output/Foundation.hs .
	ln -sf ../Bindings/ifgen-output/Foundation .
	test ! -d ../Bindings/ifgen-output/GNUstepBase || \
		ln -sf ../Bindings/ifgen-output/GNUstepBase .
	test ! -r ../Bindings/ifgen-output/GNUstepBase.hs || \
		ln -sf ../Bindings/ifgen-output/GNUstepBase.hs .
	mkdir -p build/objects
	mkdir -p build/imports
	$(GHC) --make Foundation.hs	\
		-package-name Foundation	\
		-odir build/objects \
		-hidir build/imports	\
		-package-conf ../HOC/HOC-$(PLATFORM).conf-inplace \
		-fglasgow-exts
	test ! -r GNUstepBase.hs || \
		$(GHC) --make GNUstepBase.hs	\
			-package-name Foundation	\
			-odir build/objects \
			-hidir build/imports	\
			-package-conf ../HOC/HOC-$(PLATFORM).conf-inplace \
			-fglasgow-exts
	touch $@

HSFoundation.o: ghcmake.build-stamp
	find build/objects/ -name \*.o | xargs ld -r -x -o HSFoundation.o

#libHSFoundation.a: ghcmake
#	find build/objects/ -name \*.o | xargs libtool -static -o libHSFoundation.a	

libHSFoundation.a: HSFoundation.o
	rm -f libHSFoundation.a
	ar cq libHSFoundation.a HSFoundation.o
	ranlib libHSFoundation.a

clean:
	rm -rf build libHSFoundation.a HSFoundation.o Foundation.hs \
	    Foundation ghcmake.build-stamp
	
install: all
	mkdir -p $(GHC_LIB_PATH)/Foundation
	cp -R libHSFoundation.a HSFoundation.o build/imports \
		$(GHC_LIB_PATH)/Foundation/
	ranlib $(GHC_LIB_PATH)/Foundation/libHSFoundation.a
	$(GHC_PKG) --update-package	\
			--input-file=Foundation.conf

